<template>
  <div class="login-page-container">
    <div class="swiper-content">
      <photo-swiper></photo-swiper>
    </div>
    <div class="login-container">
      <div class="logo">
        <img class="img-logo" src="/img/sailheader-log.png" alt="sailheader" />
      </div>
      <div class="user-login-container">
        <!--        <div class="title-container">-->
        <!--          <span>欢迎登录</span>-->
        <!--          <span class="split-line"> / </span>-->
        <!--          <span>MES制造执行系统</span>-->
        <!--        </div>-->
        <div>
          <div>
            <el-tabs v-model="tabName" class="table-title">
              <el-tab-pane label="系统登录" name="userLogin">
                <userLogin></userLogin>
              </el-tab-pane>
              <el-tab-pane label="作业登录" name="lineLogin">
                <lineLogin></lineLogin>
              </el-tab-pane>
            </el-tabs>
          </div>
        </div>
      </div>
      <footer class="login-footer">{{ copyright }}</footer>
    </div>
    <div class="setting-btn" @click="openLoginSet">
      <div class="setting-text">
        <i class="el-icon-setting"></i>
        <span class="text">系统设置</span>
      </div>
    </div>
    <el-dialog class="loginSetModal" title="登录设置" append-to-body :visible.sync="isShowLoginSet" width="25%" @close="closeDialog">
      <avue-form ref="loginSet" :option="loginSetOption" v-model="loginSetForm" />
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" size="small" @click="saveLoginSet"><i class="el-icon-circle-plus-outline"></i><span>保 存</span></el-button>
        <el-button size="small" @click="isShowLoginSet = false"><i class="el-icon-circle-close"></i><span>取 消</span></el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import userLogin from '@/page/login/userlogin';
import lineLogin from '@/page/login/line-login';
import photoSwiper from '@/page/login/photoSwiper';
import { checkWorkstation, getWorkstationList } from '@/api/user';
export default {
  name: 'refactor-login',
  components: {
    userLogin,
    lineLogin,
    photoSwiper
  },
  data() {
    return {
      tabName: 'userLogin',
      isShowLoginSet: false,
      loginSetForm: {},
      loginSetOption: {
        submitBtn: false,
        emptyBtn: false,
        column: [
          {
            label: '租户',
            prop: 'tenantId',
            span: 24,
            rules: [
              {
                required: true,
                message: '请输入租户ID',
                trigger: 'blur'
              }
            ]
          },
          {
            label: '工序',
            prop: 'routeCode',
            type: 'select',
            span: 24,
            dicData: [],
            props: {
              label: 'name',
              value: 'code'
            },
            focus: () => {
              this.getWorkstation();
            }
          },
          {
            label: '工位',
            prop: 'stationCode',
            span: 24
          }
        ]
      },
      workstationList: []
    };
  },
  created() {
    this.updateScale(); // 创建时更新一次缩放比例
    window.addEventListener('resize', this.updateScale); // 监听窗口大小变化
  },
  destroyed() {
    window.removeEventListener('resize', this.updateScale); // 移除监听器
  },
  methods: {
    updateScale() {
      let deviceWidth = document.documentElement.clientWidth; //获取当前分辨率下的可是区域宽度
      let scale = deviceWidth / 1920; // 分母——设计稿的尺寸
      document.documentElement.style.zoom = scale;
    },
    closeDialog() {
      this.$refs.loginSet.resetFields();
      this.loginSetForm = {};
    },
    saveLoginSet() {
      this.$refs.loginSet.validate((valid, done) => {
        if (valid) {
          if (this.loginSetForm.stationCode) {
            checkWorkstation(this.loginSetForm.stationCode, this.loginSetForm.tenantId).then((res) => {
              this.stationInfo = res.data.data;
              localStorage.setItem('loginSet', JSON.stringify(this.loginSetForm));
              localStorage.setItem('loginSetStationInfo', JSON.stringify(this.stationInfo));
              this.isShowLoginSet = false;
            });
          } else {
            localStorage.setItem('loginSet', JSON.stringify(this.loginSetForm));
            this.isShowLoginSet = false;
          }
          done();
        }
      });
    },
    openLoginSet() {
      this.isShowLoginSet = true;
      this.loginSetForm = JSON.parse(localStorage.getItem('loginSet'));
      if (this.loginSetForm && this.loginSetForm.tenantId) {
        this.getWorkstation();
      }
    },
    getWorkstation() {
      const column = this.findObject(this.loginSetOption.column, 'routeCode');
      if (!this.loginSetForm.tenantId) {
        this.$message({
          type: 'warning',
          message: '请先输入租户ID！'
        });
        column.dicData = [];
        return;
      }
      getWorkstationList(this.loginSetForm.tenantId).then(
        (res) => {
          column.dicData = this._get(res, 'data.data', []);
        },
        (error) => {
          column.dicData = [];
        }
      );
    },
    handleLogin() {
      console.log('sxxx');
    }
  },
  computed: {
    copyright() {
      return `copyright@${this.$moment(new Date()).format('YYYY')} 深圳赛瀚德技术有限公司`;
    }
  }
};
</script>

<style scoped lang="scss">
.login-page-container {
  position: relative;
  width: 100%;
  height: 100%;
  align-items: center;
  display: flex;
  background: #ffffff;
  .login-container {
    width: 61.8%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    .logo {
      display: flex;
      align-items: center;
      justify-content: flex-start;
      width: 40%;
      color: #ffffff;
      box-sizing: content-box;
      margin-top: 36px;
      height: 80px;
      .img-logo {
        width: 219px;
        height: 49px;
      }
    }
    ::v-deep .table-title {
      .el-tabs__item {
        font-size: 17px;
        line-height: 27px;
      }
    }
    ::v-deep .el-tabs__nav-wrap::after {
      width: 0;
    }
    .user-login-container {
      width: 560px;
      height: 485px;
      padding: 50px 45px;
      box-sizing: border-box;
      background: #ffffff;
      // box-shadow: 0px 0px 20px 0px rgba(7, 116, 206, 0.2);
      border-radius: 30px;
      .title-container {
        font-size: 28px;
        font-weight: 100;
        color: #333333;
        line-height: 42px;
        .split-line {
          font-weight: 200;
          color: #2192f1;
          line-height: 52px;
        }
        .system-name {
          font-weight: 500;
          color: #666666;
        }
      }
      ::v-deep .el-input {
        .el-input__inner {
          border: none;
          font-size: 20px;
        }
      }
    }
    .login-footer {
      margin-top: 116px;
      font-size: 14px;
      font-weight: 300;
      color: #c5c8df;
      line-height: 25px;
      //position: absolute;
      //bottom: 43px;
    }
  }
  .swiper-content {
    width: 38.2%;
    height: 100%;
  }

  .table-title {
    ::v-deep .el-tabs__item {
      font-size: 16px;
      line-height: 18px;
    }
  }

  ::v-deep .el-input {
    .el-input__inner {
      height: 47px;
      line-height: 47px;
      background: #fff !important;
    }

    .el-input__prefix {
      i {
        padding: 0 5px;
        font-size: 16px !important;
      }
    }
    .el-input__suffix-inner {
      height: 40px;
      display: block;
      width: 40px;
      margin-top: 2px;
    }
  }
  .setting-btn {
    display: flex;
    align-items: center;
    position: absolute;
    top: 40px;
    right: 43px;
    width: 106px;
    height: 30px;
    z-index: 9999;
    background: rgba(1, 16, 53, 0.5);
    border-radius: 17px;
    color: #fff;
    .setting-text {
      margin-left: 16px;
      font-size: 14px;
      .text {
        margin-left: 4px;
      }
    }
  }
}
</style>
